const express = require('express');
const cors = require('cors');
const Sequelize = require('sequelize');
const app = express();

const sequelize = new Sequelize('data', 'root', 'root', {
  host: '172.23.164.173',
  dialect: 'mysql',
});

const Report = sequelize.define('report_data', {
  id: {
    type: Sequelize.BIGINT,
    primaryKey: true,
    autoIncrement: true,
  },
  equipment_id: {
    type: Sequelize.BIGINT,
  },
  report_data: {
    type: Sequelize.DOUBLE,
  },
  report_date: {
    type: Sequelize.BIGINT,
  },
},{
  timestamps:false,
});

app.use(cors())

app.get('/api/data', (req, res) => {
  Report.findAll().then((reports) => {
    res.send(reports);
  }).catch((error) => {
    console.error(error);
    res.status(500).send('Server Error');
  });


    // const data = { a: 'Hello' }; 
    // res.setHeader('Content-Type', 'application/json');
    // res.send(JSON.stringify(reportDatas));
});

app.listen(3000, () => {
  console.log('Server started on port 3000');
});

